import request from './request'

export interface CartItem {
  id: number
  bookId: number
  quantity: number
  book: {
    id: number
    title: string
    price: number
    cover: string
  }
}

export const getCart = () => {
  return request({
    url: '/cart',
    method: 'get'
  })
}

export const addToCart = (bookId: number, quantity: number) => {
  return request({
    url: '/cart',
    method: 'post',
    data: { bookId, quantity }
  })
}

export const updateCartItem = (id: number, quantity: number) => {
  return request({
    url: `/cart/${id}`,
    method: 'put',
    data: { quantity }
  })
}

export const removeFromCart = (id: number) => {
  return request({
    url: `/cart/${id}`,
    method: 'delete'
  })
}

export const checkout = () => {
  return request({
    url: '/cart/checkout',
    method: 'post'
  })
} 